<?php

namespace app\admin\command;

use app\admin\model\Reserve;
use app\admin\model\Room;
use app\common\library\Yunding;
use Carbon\Carbon;
use think\console\Command;
use think\console\Input;
use think\console\input\Option;
use think\console\Output;
use think\Db;
use think\Env;
use think\Exception;
use think\Log;

class ReleasePassword extends Command
{

    protected function configure()
    {
        $this->setName('release_password')
            ->setDescription('release password');
    }

    protected function execute(Input $input, Output $output)
    {
        @ini_set("memory_limit",'-1');
        $stime=microtime(true);

        $daysLaterReserves = Reserve::with(['room', 'store'])->where('starttime', '>', Carbon::parse('2022-07-14 00:00:00')->toDateTimeString())
            ->where('re_status', 1)
            ->select();

        $yunding = new Yunding();
        foreach ($daysLaterReserves as $reserve) {
            echo $reserve->starttime;
            $result = $yunding->deletePassword($reserve->room->yunding_homeid, $reserve->room->yunding_uuid, $reserve->yunding_password_id);

            echo $result ? 'ok' : 'no';
            echo PHP_EOL;
        }

        $etime=microtime(true);//获取程序执行结束的时间
        $total=$etime-$stime;   //计算差值
        $output->writeln($total);
    }

}
